﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ScoreMS.Views
{
    /// <summary>
    /// Examination_paperView.xaml 的交互逻辑
    /// </summary>
    public partial class Examination_paperView : Page
    {
        public Examination_paperView()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Examination_paperView_Loaded);
        }

        void Examination_paperView_Loaded(object sender, RoutedEventArgs e)
        {
            this.cbxCourse.ItemsSource = BLL.CourseBS.GetCourseList(App.teacher_id);
        }

        private void cbxCourse_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if(this.cbxCourse.SelectedIndex == -1) return;
            var model = cbxCourse.SelectedItem as Model.Course;
            this.dataGrid1.ItemsSource = BLL.Examination_paparBS.GetExamination_paparList(model.course_id);
        }

        private void DataGridHyperlinkColumn_Click(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var ex_id = (sender as Button).Tag.ToString();
            //App.Current.Properties["frame"] = ex_id.ToString(); //!

            var frame = GetVisualParentByType<Frame>(this);
            frame.Navigate(new Uri("Views/Examination_paperEdit.xaml", UriKind.Relative), ex_id);
            //NavigationService.Navigate(new Uri("Views/Examination_paperEdit.xaml", UriKind.Relative));
        }

        public static T GetVisualParentByType<T>(DependencyObject child)
            where T : DependencyObject
        {
            var parent = VisualTreeHelper.GetParent(child);
            if (parent == null)
                return null;

            var TypedParent = parent as T;
            if (TypedParent != null)
                return TypedParent;
            else
                return GetVisualParentByType<T>(parent);
        }

    }
}
